// 引入axios
import axios from "axios";
import { Message } from "element-ui";
import Nprogress from "nprogress";
import "nprogress/nprogress.css";
// 创建新的axios
let http = axios.create({
    // baseURL: 'https://www.liulongbin.top:8888/api/private/v1/',
    // baseURL: 'http://localhost:8888/api/private/v1',
    baseURL: "http://api.yyqmax.cloud/api/private/v1",

    timeout: 3000
})
// 设置请求拦截y

http.interceptors.request.use(
    // 请求成功回调
    config => {
        Nprogress.start()
        // if(config.url != '/'){
        //     let token = localStorage.getItem('token')
        //     token && (config.headers.Authorization = token)
        // }
        config.headers.Authorization = localStorage.getItem('token');
        return config
    },
    (err) => {
        return Promise.reject(err)
    }
)

// 设置响应拦截
http.interceptors.response.use(
    // 响应成功回调函数
    (result) => {
        Nprogress.done();
        Message({
            message: result.data.meta.msg,
            type: 'success'
        });
        return Promise.resolve(result)
    },
    (err) => {
        Nprogress.done();
        return Promise.reject(err)
    }
)

// 导出http
export default http